import { defineConfig } from 'vite'
import react from '@vitejs/plugin-react-swc'
import viteCompression from 'vite-plugin-compression'
import legacyPlugin from '@vitejs/plugin-legacy'
import { join } from 'path';

export default defineConfig({
  resolve: {
    alias: {
      '@': join(__dirname, 'src')
    }
  },
  plugins: [react(), viteCompression({
    algorithm: 'gzip',
    ext: '.gz',
    threshold: 10240,
    disable: false,
    verbose: true,
  }),
  legacyPlugin({
    targets: ['chrome 52'],
    additionalLegacyPolyfills: ['regenerator-runtime/runtime']
  })
  ],
  server: {
    host: '0.0.0.0'
  },
  build: {
    terserOptions: {
      compress: {
        drop_console: false,
        drop_debugger: true
      }
    },
    rollupOptions: {
      output: {
        chunkFileNames: "static/js/[name]-[hash].js",
        entryFileNames: "static/js/[name]-[hash].js",
        assetFileNames: 'static/[ext]/[name]-[hash].[ext]'
      },
      manualChunks(id) {
        if (id.includes("node_modules")) {
          return "vendor"
        }
        if (id.includes("views/modules")) {
          return "views-modules"
        }
        if (id.includes("views/common")) {
          return "views-common"
        }
      }
    }
  }
})
